package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    // 用户id+菜品id 或者 用户id+套餐id 查询购物车是否存在
    ShoppingCart findOne(ShoppingCart shoppingCart);

    // 更新数据库
    void update(ShoppingCart shoppingCartDB);

    // 保存购物车
    @Insert("insert into shopping_cart values(null,#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime})")
    void save(ShoppingCart shoppingCart);

    // 根据用户id查询购物车
    @Select("select * from shopping_cart where user_id=#{userId}")
    List<ShoppingCart> findByUserId(Long userId);

    // 根据用户id删除购物车
    @Delete("delete from shopping_cart where user_id=#{userId}")
    void deleteByUserId(Long userId);

    //删除购物车中的菜品或套餐
    @Delete("delete from shopping_cart where id=#{id}")
    void deleteById(Long id);
}
